<?
include("/var/www/html/new/conf/r.le.je");
$le=new go_sql();
$le->connect(); 
include("../com.inc.php");

if (!class_exists("cpaint")){
  include("../cpaint/cpaint2.inc.php");
}
  $cp=new cpaint();


function get_hot_city(){
	$node=$GLOBALS['cp']->add_node("get_hot_city_n");	
	$dtext="";
	$hotcity=array();
	
	$str="select city_name,city_3code from air_city where hot='1'";
    $GLOBALS['le']->query($str);
    while($row=$GLOBALS['le']->fetch_assoc()){
	$hotcity[]=$row;	
	}
	
$dtext.="1 |";
foreach ($hotcity as $val) {
$dtext.="<a href='javascript:void[0]' onmouseup=set_f_city('".$val[city_3code]."','".$val[city_name]."')";
$dtext.=">".$val[city_name]."</a>";		
}
	$node->set_data($dtext);
    return;		
}

function change_f_city($num){
	$node=$GLOBALS['cp']->add_node("change_f_city_n");	
	$dtext="";
	$hotcity=array();

$a1=array("1","'A','B','C','D','E','F'","'G','H','I','J'","'K','L','M','N'","'O','P','Q','R','S','T','U','V','W'","'X','Y','Z'");
$anum=$a1[$num];
if ($anum!="1"){
	$str="select city_name,city_3code from air_city where location=0 and getPY(city_name,1) in (".$anum.")";
}else{
	$str="select city_name,city_3code from air_city where hot='1'";
}
    $GLOBALS['le']->query($str);
    while($row=$GLOBALS['le']->fetch_assoc()){
	$hotcity[]=$row;	
	}
	
$dtext.="1 |";
foreach ($hotcity as $val) {
$vcname=str_replace(' ','　',$val[city_name]);
$vcname=htmlspecialchars($vcname);
$dtext.="<a href='javascript:void[0]' onmouseup=set_f_city('".$val[city_3code]."','".$vcname."')";
$dtext.=" title='".$vcname."'";
$dtext.=">".mbsubstr($vcname,6)."</a>";

//$dtext.="<a href='1.html' onmouseup=set_f_city('ABC','".$vcname."')>".mbsubstr($val[city_name],6)."</a>";

}
	$node->set_data($dtext);
    return;		
}


function search_f_city($words){
	$node=$GLOBALS['cp']->add_node("search_f_city_n");	
	$dtext="";
if ($words && p_match($words)){
	$dtext.="0 | 含有非法字符！搜索无法继续！";
	$node->set_data($dtext);
    return;	
} elseif(!$words){
	$dtext.="0 | 请输入至少1个字符才能搜索！";
	$node->set_data($dtext);
    return;		
}

if (!preg_match('/[\x00-\x7F]/', $words)){
$str="select city_name,city_3code,airport_name from air_city where location=0 and (city_name like '".$words."%' or airport_name like '%".$words."%')";									
}else{

//构建where
$lens=str_len2($words);
$where="";
for ($i=1;$i<=$lens;$i++){
$where.=" and getPY(city_name,$i)=getPY('$words',$i)";	
}
	$str="select city_name,city_3code,airport_name from air_city where location=0";
	$str.=$where;	
}

	$scity=array();

    $GLOBALS['le']->query($str);
    while($row=$GLOBALS['le']->fetch_assoc()){
	$scity[]=$row;	
	}
	$dtext.="1|";
	foreach ($scity as $val){
	$vcname=str_replace(' ','　',$val[city_name]);
	$vcname=htmlspecialchars($vcname);
	$vcname2=str_replace(' ','　',$val[airport_name]);
	$vcname2=htmlspecialchars($vcname2);
	$dtext.="<div onmouseup=set_f_city('".$val[city_3code]."','".$vcname2."')>";
	$dtext.="<span class=s1>".$vcname."</span>";	
	$dtext.="<span class=s2>".$vcname2."</span>";
	$dtext.="</div>";	
	}
//$dtext.=$str;
	$node->set_data($dtext);
    return;		
}

function loadCity_ajax($id){
	$node=$GLOBALS['cp']->add_node("loadCity_ajax_n");
	//$node1=$node->add_node("sj");

$str="select area_id,area_name from uu_area where area_parent_id='$id' and area_deeppath='2'";
$GLOBALS['le']->query($str);
$p=array();
while ($row=$GLOBALS['le']->fetch_assoc()){
$p[]=$row;
}

foreach ($p as $v){
$node1=$node->add_node("sj");
$node1->set_attribute("optv",$v[area_id]);
$node1->set_attribute("optn",$v[area_name]);
}

}

function loadZone_ajax($id){
	$node=$GLOBALS['cp']->add_node("loadZone_ajax_n");	
	$dtext="";

$str="select area_id,area_name from uu_area where area_parent_id='$id' and area_deeppath='3'";
$GLOBALS['le']->query($str);
$p=array();
while ($row=$GLOBALS['le']->fetch_assoc()){
$p[]=$row;
}

foreach ($p as $v){
$node1=$node->add_node("sj");
$node1->set_attribute("optv",$v[area_id]);
$node1->set_attribute("optn",$v[area_name]);
}	
}

function u_example(){
	$node=$GLOBALS['cp']->add_node("u_example_n");	
	$dtext="";

	$node->set_data($dtext);
    return;		
}

$cp->register("get_hot_city");
$cp->register("change_f_city");
$cp->register("search_f_city");
$cp->register("loadCity_ajax");
$cp->register("loadZone_ajax");

$cp->start();
$cp->return_data();
?>